package app.netant.book.socitys;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class SocitysDetail extends BaseDetail {

	public SocitysDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.socitys.cn";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#main #bookinfo .ti h1");
		if(parts.size()>0){
			String title = parts.get(0).text().trim();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts2 = this.select("#main #bookinfo .ti p");
		if(parts2.size()>0){
			String writer = parts2.get(0).text().trim();		
			int idx = writer.indexOf("：");
			if(idx>0){
				writer = writer.substring(idx+1);
				System.out.println("【Writer】:"+writer);
				this.entity.setNovelWriter(writer);
			}
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#main #bookinfo .ti ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#main #bookinfo .ti #bookintro #bookintroinner");
		if(parts.size()>0){
			String memo = parts.get(0).text().trim();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#main #bookinfo .item .xxbut a.but_xz");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			System.out.println("【Href】:"+href);
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#location a");
		if(parts.size()>1){
			String type = parts.get(1).text().trim();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		SocitysDetail detail = new SocitysDetail("http://www.socitys.cn/shu/31505.html");
		detail.test();
	}



}
